import 'package:flutter/material.dart';

void main() => runApp(MyApp());

//  @required 编译能通过，只是报警告，但是运行不通过。必传参数，编译都不能通过！
class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Material App',
      home: Scaffold(
        appBar: AppBar(
          title: Text('Material App Bar'),
        ),
        body: HomePage(),
        floatingActionButtonLocation: FloatingActionButtonLocation.endFloat,
        floatingActionButton: FloatingActionButton(
          child: Icon(Icons.add),
          onPressed: () {},
        ),
      ),
    );
  }
}

class HomePage extends StatefulWidget {
  @override
  _HomePageState createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  @override
  Widget build(BuildContext context) {
    return Column(
      children: <Widget>[
        RaisedButton(
          child: Text("RaisedButton"),
          textColor: Colors.white,
          color: Colors.orange,
          onPressed: () {
            print("凸起Button");
          },
        ),
        FlatButton(
          child: Text("FlatButton"),
          textColor: Colors.white,
          color: Colors.lightBlue,
          onPressed: () {
            print("扁平Button");
          },
        ),
        ButtonTheme(
          minWidth:30,
          height:10,
//            final ThemeData theme = Theme.of(context);
//            源码中button的大小是通过theme定义的，默认是88*36，而他的theme又是从context上下文中去的，所以设置它的大小要在button外嵌套一个ButtonTheme
          child:FlatButton(
            child: Text("button2"),
            padding: EdgeInsets.all(0),
            materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
            color: Colors.red,
            onPressed: () {},
          ),
        ),
        OutlineButton(
          child: Text("OutlineButton"),
          textColor: Colors.red,
          color: Colors.amber,
          onPressed: () {
            print("边框Button");
          },
        ),
        // 自定义button 图标-文字-背景-圆角
        FlatButton(
          color: Colors.yellow,
          shape: RoundedRectangleBorder(
            borderRadius: BorderRadius.circular(6),
          ),
          child: Row(
            // mainAxisAlignment: MainAxisAlignment.center,
            mainAxisSize: MainAxisSize.min,
            children: <Widget>[
              Icon(
                Icons.favorite,
                color: Colors.red,
              ),
              Text("喜欢作者"),
            ],
          ),
          onPressed: () {},
        ),
      ],
    );
  }
}
